package com.example.fragmenttest.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.example.fragmenttest.R;
import com.example.fragmenttest.communication.CommunicationInterface;
import com.example.fragmenttest.fragment.MyFragment;

public class Main2Activity extends AppCompatActivity implements CommunicationInterface {


    @Override
    public void sendDataToActivity(Bundle data) {
        // 实现数据发送逻辑
    }

    @Override
    public void receiveDataFromFragment(Bundle data) {
        // 实现数据接收逻辑
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // 在目标Activity中创建Fragment并附加数据
        Fragment newFragment = new MyFragment();
        Bundle args = new Bundle();
        args.putString("user_name", "Alice");
        newFragment.setArguments(args);
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.test_fragment, newFragment).commit();


    }
}